/*
 * Copyright 2008 [rapid-framework], Inc. All rights reserved.
 * Website: http://www.rapid-framework.org.cn
 */

    define("pages/jls_dyflxgws/form", [
            '../../pages/jls_dyflxgws/DyflxgwsForm.html.js',
            "../../common/componts",
        ],
        function(require){
            var _show=function(_title,_data){
                var comonts=require("../../common/componts");
                var tmp= require("../../pages/jls_dyflxgws/DyflxgwsForm.html");
                var htmlcompile = template.compile(tmp);
                //var _blr=loginuser.username;//获取当前办理人
                var html = htmlcompile(
                    {
                        title:_title,
                        data:_data
                    });
                $("#dlgDyflxgws").dialog('destroy');
                $("#dyflxgwsForm").html(html);
                comonts.initSelect(undefined,undefined,undefined);
                $.parser.parse($("#dyflxgwsForm").parent());
                $('#dlgDyflxgws').window('open');
                bindAction();
            }
            var saveDyflxgws=function () {
                var validate=$("#dlgDyflxgws").form('validate');
                if (validate) {
                    var data =$("#fmDyflxgws").serialize();
                    submitLoad();
                    $.ajax({
                        type : "POST",  //提交方式
                        url : "/jls_dyflxgws/dyflxgwsAdd",//路径
                        data : data,//数据，这里使用的是Json格式进行传输
                        success : function(result) {
                            if (result.success) {
                                $('#dlgDyflxgws').dialog('close');
                                findDyflxgws();
                                $.messager.alert('提示','保存成功!','info');
                            }else{
                                removeLoad();
                                $.messager.alert('提示',result.msg,'info');
                            }
                        },
                        complete:function(){
                            removeLoad();
                        },

                    });
                }else{
                    $.messager.alert("提示", '必填项不能为空！');
                }
            }
            var updateDyflxgws=function () {
                var validate=$("#dlgDyflxgws").form('validate');
                if (validate) {
                    var data =$("#fmDyflxgws").serialize();
                    submitLoad();
                    $.ajax({
                        type : "POST",  //提交方式
                        url : "/jls_dyflxgws/dyflxgwsUpdate",//路径
                        data : data,//数据，这里使用的是Json格式进行传输
                        success : function(result) {
                            if (result.success) {
                                $('#dlgDyflxgws').dialog('close');
                                findDyflxgws();
                                $.messager.alert('提示','更新成功!','info');
                            }else{
                                removeLoad();
                                $.messager.alert('提示',result.msg,'info');
                            }
                        },
                        complete:function(){
                            removeLoad();
                        },

                    });
                }else{
                    $.messager.alert("提示", '必填项不能为空！');
                }
            }
            var bindAction=function(){
                var dyflxgwsId=$("#idfm").val();
                $("#dyflxgws_save").on("click",function(){
                    if(dyflxgwsId==""||dyflxgwsId==null){
                        saveDyflxgws();
                    }else {
                        updateDyflxgws();
                    }
                });
                $("#dyflxgws_cancel").on("click",function(){
                    $("#dlgDyflxgws").dialog("close");
                });

            }
            function findDyflxgws(){
                $('#dyflxgwsId').datagrid('clearSelections');
                $('#dyflxgwsId').datagrid('reload',{
                });
            }
            return{
                show:_show
            }
        });
